﻿// baseInterface should be the base class of the SWF.
package com.cf.core.view{
	import flash.display.Sprite;
	import flash.display.StageDisplayState;
	import flash.display.Stage;
	import flash.display.*;
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;
	import com.cf.core.Utils.*;
	import com.cf.core.view.*;
	import com.cf.core.events.LoadEvent;
	public class baseInterface extends Sprite {
		public static const FULLSCREEN:String = "FullScreen";
		public static const NORMALSCREEN:String = "NormalScreen";
		public static const TOGGLESCREEN:String = "ToggleScreen";
		private var G_inited:Boolean=false;
		private var G_var:cache;
		private var G_sound:cacheSound;
		public function get SYNC_VAR():cache{return G_var}
		public function get VAR():Function{return G_var.address}
		public function get SOUND():Function { return G_sound.child }
		public function set mute(_t:Boolean):void { G_sound.mute = _t; }
		public function get mute():Boolean { return G_sound.mute; }
		/*****************
		@ author Canis
		@ function to control the interface, soundLoop, soundFX, task, scene everything
		//****************/
		// Built-in Sound channel, Scene Control, preloadFunction
		
		public function baseInterface():void{
			dispatchEvent(new LoadEvent(LoadEvent.BEFORELOAD));
			stage.scaleMode = StageScaleMode.SHOW_ALL;
			stage.align = StageAlign.TOP_LEFT;
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}//fn
		private function init(e:Event = null):void{
			this.removeEventListener(Event.ADDED_TO_STAGE, init);
			// entry point
			if (!G_inited) {
				//
				// Game Layer Setup
				//
				G_var=new cache();
				G_inited=true;
				// SoundChannel create
				G_sound=new cacheSound(this);
				this.dispatchEvent(new LoadEvent(LoadEvent.ONLOAD));
				this.addEventListener(Event.REMOVED_FROM_STAGE, RELEASE);
			}//if
		}//fn
		public function RELEASE(e:*=null):void{
			// G_sound.RELEASE(e); // will release itself.
			this.removeEventListener(Event.REMOVED_FROM_STAGE, RELEASE);
			G_var.RELEASE();
			tools.emptySprite(this);
		}//fn
		public function normalScreen():void {
			stage.displayState=StageDisplayState.NORMAL;
		}
		public function fullscreen():void {
			stage.displayState=StageDisplayState.FULL_SCREEN;
		}
		public function togglefullScreen():void {
			// remember to turn on export's fullscreen allow. Ctrl+Shift+F12>html>allow fullscreen
			trace("baseInterface Try to "+ stage.displayState);
			if (stage.displayState == StageDisplayState.FULL_SCREEN) {
				normalScreen();
			} else {
				fullscreen();
			}//if
		}//fn
	}//class
}//package